package com.study.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;

/**
 * @program: shouxieSpring
 * @author: jzhou
 * @date: 2022-04-13 22:10
 * @version: 1.0
 * @description: fuwu
 **/
@Component("userService")
public class UserService {

	@Autowired
    private OrderService orderService;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private UserServiceBase userServiceBase;

//    @Autowired
//    private User admin;

    @PostConstruct
    public void a(){
        System.out.println("===UserService---PostConstruct===");
    }


    @Transactional
    public void test(){
        System.out.println("userService.test----"+orderService);
        jdbcTemplate.execute("");
       // b(); // 直接这样调用事务会失效，解决方法可以把b方法拆到另一个类中，或者自己注入自己
        //想要注解生效必须是代理对象来掉该方法，自己写的方法里没有对MySQL的自动提交取消操作
        userServiceBase.b();
        throw new NullPointerException();
    }

    @Transactional(propagation = Propagation.NEVER)
    public void b(){
        jdbcTemplate.execute("");
    }

}
